In [1]:
import geopandas as gpd
In [2]:
#bld = gpd.GeoDataFrame.from_file('Building Footprints.geojson')
In [2]:
import csv
import numpy as np
import matplotlib.pyplot as pl
from matplotlib import colors
import matplotlib.cm as cm
import matplotlib.colors as mcolors
import seaborn as sns
%matplotlib inline
from fiona.crs import from_epsg
import pysal as ps
import shapely as shp
import ast
from cStringIO import StringIO
import requests
import os
import json
import urllib
import urllib2
In [7]:
walk= gpd.GeoDataFrame.from_file('WalkingDist.geojson')
walk.crs
Out[7]:
In [4]:
walk.head()
Out[4]:
In [16]:
walk.to_file('WalkingDist')
walk.crs = {'init' :'epsg:4326'}
In [10]:
bld=gpd.GeoDataFrame.from_file('output/Brooklynstreets.shp')
In [11]:
bld.crs
Out[11]:
In [17]:
walk.crs
Out[17]:
In [12]:
sta =gpd.GeoDataFrame.from_file('subStations/subStations.shp')
sta.crs
Out[12]:
In [43]:
sta =gpd.GeoDataFrame.from_file('Subway Stations/geo_export_5e33d456-40a6-4bc5-83f8-d922a76657e4.shp')
sta.crs
Out[43]:
In [45]:
sta.crs_wkt
In [18]:
walk.to_crs({u'datum': u'NAD83',
u'lat_0': 40.16666666666666,
u'lat_1': 40.66666666666666,
u'lat_2': 41.03333333333333,
u'lon_0': -74,
u'no_defs': True,
u'proj': u'lcc',
u'units': u'us-ft',
u'x_0': 300000,
u'y_0': 0})
Out[18]:
In [20]:
walk.crs
Out[20]:
In [21]:
walk.to_file('therealwalk')
In [32]:
crs = {'init': 'epsg:4326'}
In [38]:
walk = gpd.read_file('WalkingDist.geojson', crs=crs)
In [39]:
walk.head()
Out[39]:
In [40]:
walk.crs
Out[40]:
In [42]:
walk.crs = {'init': 'epsg:4326'}
walk.crs
Out[42]:
In [26]:
gpd.read_file?
In [ ]:
ws = "Subway Stations/"
prj_file =gpd.datasets.get_path('geo_export_5e33d456-40a6-4bc5-83f8-d922a76657e4')
sta.crs
prj_file = gpd.datasets.get_path('naturalearth_lowres').replace(".shp",".prj")
prj = [l.strip() for l in open(prj_file,'r')][0]
world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
temp_shp = os.path.join(ws,"world_out.shp")
world.to_file(filename=temp_shp,driver='ESRI Shapefile',crs_wkt=prj)
In [48]:
prj_file =gpd.datasets.get_path('geo_export_5e33d456-40a6-4bc5-83f8-d922a76657e4.shp').replace(".shp",".prj")
prj_file
In [62]:
prj = [l.strip() for l in open('Subway Stations/geo_export_5e33d456-40a6-4bc5-83f8-d922a76657e4.prj','r')][0]
In [63]:
prj
Out[63]:
In [60]:
walk.to_file(filename='therealwalk2',driver='ESRI Shapefile',crs_wkt=prj)
In [64]:
walk = gpd.read_file('therealwalk2/therealwalk2.shp')
walk.crs
Out[64]:
In [65]:
nei = gpd.read_file('../Class_7/NYCneighbourhoods/NYCneighbourhoods.shp')
nei.crs
Out[65]:
In [66]:
nei.to_file(filename='NYCNeighbourhoods',driver='ESRI Shapefile',crs_wkt=prj)
In [3]:
import pandas as pd
import numpy as np
import geopandas as gd
import matplotlib.pylab as pl
from fiona.crs import from_epsg
import fiona
from matplotlib import colors
import shapely
import seaborn as sns
%matplotlib inline
In [23]:
import requests
import time
url = "https://api.yelp.com/v3/businesses/search"
def yelp(x,y,r):
querystring = {"latitude":str(x),"longitude":str(y),"radius":str(r),"limit":str(50)}
headers = {
'authorization': "Bearer BLFZLp20YRlPJFKs6htUY824brFnUTfsbdsYapxcBoBYXTnOYjwFaH1wr0BK7i6lMbLZlVvAFgG3OE6MAQY849BTw1arAuHGevfHh6TRCsVwMnG2GXqejJTWRzErWXYx",
'cache-control': "no-cache",
'postman-token': "e903653d-085f-354b-96fb-19691e66f5ba"
}
time.sleep(.25)
response = requests.request("GET", url, headers=headers, params=querystring)
return response.json()
#print(response.text)
In [5]:
sta =gpd.GeoDataFrame.from_file('Subway Stations/geo_export_5e33d456-40a6-4bc5-83f8-d922a76657e4.shp')
In [6]:
sta.head()
Out[6]:
In [7]:
stal = sta[sta.line=='L']
stal
Out[7]:
In [48]:
cloud= gpd.GeoDataFrame.from_file('output/pointcloud.shp')
cloud.crs
cloud.head()
Out[48]:
In [50]:
cloud = cloud.to_crs(epsg=4326)
In [51]:
cloud.plot()
Out[51]:
In [54]:
cloud.head()
Out[54]:
In [8]:
stal.drop([442,441,383,382,145], inplace=True)
In [9]:
#f, ax = pl.subplots(figsize=(55,55))
stal.plot()
#pl.axis('off')
#ticks = ax.set_xticklabels(ax.get_xticklabels(), rotation = 90)
Out[9]:
In [24]:
stal.geometry[71].y
Out[24]:
In [73]:
columns = [
'yelp_lat',
'yelp_long',
'yelp_distance',
'yelp_name',
'yelp_street',
'yelp_city',
'yelp_state',
'yelp_zip_code',
'yelp_cat1',
'yelp_cat2',
]
index = pd.Series(range(stal.shape[0]*3457))
df = pd.DataFrame(index=None, columns=columns)
df = df.fillna(0)
df.head()
Out[73]:
In [74]:
def getx(point):
return point.x
def gety(point):
return point.y
In [75]:
cloud.shape
Out[75]:
In [76]:
addressold = ''
old_index = np.nan
count=0
#customer_iter = iter(Customer_Info.index)
yelp_cat1 =[]
yelp_cat2 =[]
yelp_lat=[]
yelp_long=[]
yelp_distance=[]
yelp_name=[]
yelp_street=[]
yelp_city=[]
yelp_state=[]
yelp_zip_code=[]
for i in cloud.index:
print i,count
r_json = yelp(gety(cloud.ix[i,'geometry']), getx(cloud.ix[i,'geometry']), 100)
print len(r_json['businesses'])#, r_json['businesses']
if len(r_json['businesses'])>0:
for j in range(len(r_json['businesses'])):
if r_json['businesses'][j][u'categories']!=[]:
yelp_cat1.append(r_json['businesses'][j][u'categories'][0][u'alias'])
yelp_cat2.append(r_json['businesses'][j][u'categories'][0][u'title'])
yelp_lat.append(r_json['businesses'][j][u'coordinates'][u'latitude'])
yelp_long.append(r_json['businesses'][j][u'coordinates'][u'longitude'])
yelp_distance.append(r_json['businesses'][j][u'distance'])
yelp_name.append(r_json['businesses'][j]['name'])
yelp_street.append(r_json['businesses'][j][u'location'][u'address1']) #Street
yelp_city.append(r_json['businesses'][j][u'location']['city'])
yelp_state.append(r_json['businesses'][j][u'location']['state'])
yelp_zip_code.append(r_json['businesses'][j][u'location'][u'zip_code'])
count+=1
if count==2000:
break
df.yelp_cat1=yelp_cat1
df.yelp_cat2=yelp_cat2
df.yelp_lat=yelp_lat
df.yelp_long=yelp_long
df.yelp_distance=yelp_distance
df.yelp_name=yelp_name
df.yelp_street=yelp_street
df.yelp_city=yelp_city
df.yelp_state=yelp_state
df.yelp_zip_code=yelp_zip_code
In [77]:
df.shape[0]
Out[77]:
In [78]:
df.drop_duplicates().shape[0]
Out[78]:
In [79]:
df.head()
Out[79]:
In [80]:
df.drop_duplicates().shape[0]
Out[80]:
In [82]:
df1 = df.drop_duplicates()
In [84]:
df1.to_csv('output/business.csv', encoding='utf-8')
In [85]:
#re in a conda env: conda install -c conda-forge imageio
!pip install imageio
#Good old python setup.py install
In [1]:
from PIL import Image
In [3]:
img = Image.open("Data/2-0normal.gif")
In [4]:
img2 = img.crop((0, 0, 100, 100))
#img2.save("img2.jpg")
In [ ]:
re in a conda env: conda install -c conda-forge imageio
If you have pip: pip install imageio
Good old python setup.py install